//
//  WXToolBarView.swift
//  weibo
//
//  Created by 王旭 on 16/4/21.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit

class WXTabBarView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        //1.添加控件
        let retweetButton = addChildBUtton("转发", imageNamed: "timeline_icon_retweet")
        let commentutton = addChildBUtton("评论", imageNamed: "timeline_icon_comment")
        let likeButton = addChildBUtton("赞", imageNamed: "timeline_icon_unlike")
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(sp1);addSubview(sp2)
        
        //2.做约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentutton)
        }
        commentutton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(likeButton)
        }
        likeButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentutton.snp_trailing)
            make.top.bottom.trailing.equalTo(self)
            make.width.equalTo(retweetButton)
        }
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentutton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
    }
    
    private func addChildBUtton(title:String, imageNamed:String)->UIButton {
        let button = UIButton(titleColor: UIColor.darkGrayColor(), fontSize: TabBarButtonFontSize)
        //标题
        button.setTitle(title, forState: .Normal)
        //图片
        button.setImage(UIImage(named: imageNamed), forState: .Normal)
        //不同状态下背景图
    button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background_highlighted"), forState: .Highlighted)
    button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background" ), forState: .Normal)
        addSubview(button)
        return button
    }

}
